<template>
    <div class="page_list">
        <header class="header">
            <el-select size="mini" v-model="parames.siteId" placeholder="请选择">
                <el-option
                        v-for="item in options"
                        :key="item.value"
                        :label="item.siteName"
                        :value="item.siteId">
                </el-option>
            </el-select>
            页面别名:
            <el-input size="mini" v-model="parames.pageAliase" style="width: 100px;margin-right: 10px;"></el-input>
            <el-button size="mini" type="primary" @click="query">查询</el-button>
            <router-link  :to="{path:'/cms/page/add/',query:{page: this.params.page,siteId: this.parames.siteId}}"
                         style="margin-left: 10px;">
                <el-button size="mini" type="primary">新增</el-button>
            </router-link>
        </header>
        <el-table  :data="list" stripe style="width:100%">
            <el-table-column type="index" width="60">  
                   
            </el-table-column>
               
            <el-table-column prop="pageName"  label="页面名称">   
                  
            </el-table-column>
             
            <el-table-column prop="pageAliase"  label="别名">  
                   
            </el-table-column>
              
              
            <el-table-column prop="pageType"  label="页面类型">   
                  
            </el-table-column>
              
              
            <el-table-column prop="pageWebPath"  label="访问路径">
                    
            </el-table-column>

            <el-table-column prop="pagePhysicalPath"  label="物理路径">

            </el-table-column>

            <el-table-column prop="pageCreateTime"  label="创建时间">

            </el-table-column>
            <el-table-column  label="操作1">
                <template slot-scope="scope">
                    <el-button size="small" type="text" @click="edit(scope.row.pageId)">编辑</el-button>
                    <el-button size="small" type="text" @click="deleteById(scope.row.pageId)">删除</el-button>
                </template>
            </el-table-column>
             
        </el-table>
        <div class="block" style="text-align: right">
            <el-pagination
                    layout="prev, pager, next"
                    @current-change="handleCurrentChange"
                    :page-size="params.size"
                    :current-page="params.page"
                    :total="total">
            </el-pagination>
        </div>
    </div>
</template>

<script>
    import {mapState, mapActions,mapMutations} from "vuex"
    import {page_deleteById} from "@/module/cms/api/cms";

    export default {
        data() {
            return {
                options: [
                    {
                        siteId: '5a751fab6abb5044e0d19ea1',
                        siteName: '门户主站'
                    },
                    {
                        siteId: '102',
                        siteName: '测试'
                    }
                ],
                params: {
                    page: 2,
                    size: 5,

                },
                parames: {
                    pageAliase: "",
                    siteId: '',
                    siteName: ''
                }
            }
        },
        props: {
            query: {
                type: Object,
                default: {}
            },
        },
        methods: {
            ...mapActions(['getPage_list']),
            ...mapMutations(['setPageEditUrl']),
            querys() {
                this.getPage_list({params: this.params, parames: this.parames})
            },
            handleCurrentChange(val) {
                this.$router.push({path: '/cms/page/list', query: {page: val, siteId: this.parames.siteId}});
                this.params.page = val;
                this.querys();
            },
            edit(page) {
                this.setPageEditUrl({page: this.params.page,siteId: this.parames.siteId});
                this.$router.push({path:"/cms/page/edit/"+page})
            },
            deleteById(id){
                this.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning'
                }).then(() => {
                    page_deleteById(id).then((res)=>{
                        this.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                        this.querys();
                    }).catch((e)=>console.log(e))
                }).catch(() => {
                    this.$message({
                        type: 'info',
                        message: '已取消删除'
                    });
                });
            }
        },
        created() {
            this.params.page = Number.parseInt(this.query.page || 1);
            this.parames.siteId = this.query.siteId || '';
            this.querys();
        },
        computed: {
            ...mapState({
                list: state => state.cms.list,
                total: state => state.cms.total
            }),

        }
    }
</script>

<style scoped>
    .header {
        padding: 15px 0;
    }
</style>
